package com._54programer.demo.packet.ok;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ReplayingDecoder;

import java.util.List;

/**
 * @author SN
 * @date Created by on 2019/11/30
 * @description
 */
public class MessageProtocolDecoder extends ReplayingDecoder<Void> {
    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf in, List<Object> out) throws Exception {
        //1.获取二进制数据
        int len = in.readInt();
        byte[] content = new byte[len];
        in.readBytes(content);
        //2.将二进制数据疯转成MessageProtocol对象
        MessageProtocol messageProtocol = new MessageProtocol();
        messageProtocol.setLen(len);
        messageProtocol.setContent(content);
        //3.通过out传递给下一个Handler业务处理
        out.add(messageProtocol);
    }
}
